import { createApp } from 'vue'
import App from './App.vue'

// 引入 antd样式表， 否则没有message提示
// import { message } from 'ant-design-vue';
import 'ant-design-vue/dist/antd.less'

import './global.less' // global style

// pro-layout vue版本组件
import ProLayout from '@ant-design-vue/pro-layout'

// 导入 pro-layout 的样式文件
import '@ant-design-vue/pro-layout/dist/style.less'

import {VueClipboard} from '@soerenmartius/vue3-clipboard' //复制插件 https://github.com/soerenmartius/vue3-clipboard

// vue路由
import router from './router'

// 使用 pinia 替换掉 vuex
import { createPinia } from 'pinia'

//引入bootstrap图标库
import 'bootstrap-icons/font/bootstrap-icons.css'

import icons from './icons'

import infoBox from '@/utils/infoBox'

import { setSiteInfos } from './oemconfig'

import { setGlobalApp } from '@/config/appConfig'

// 图片预览组件  https://mirari.cc/2021/05/31/Vue3%E5%9B%BE%E7%89%87%E6%B5%8F%E8%A7%88%E7%BB%84%E4%BB%B6v-viewer%EF%BC%8C%E6%94%AF%E6%8C%81%E6%97%8B%E8%BD%AC%E3%80%81%E7%BC%A9%E6%94%BE%E3%80%81%E7%BF%BB%E8%BD%AC%E7%AD%89%E6%93%8D%E4%BD%9C/
import 'viewerjs/dist/viewer.css'
import VueViewer from 'v-viewer'

// userStore
import {useUserStore} from '@/store/modules/user'

const app = createApp(App)

app.config.warnHandler = () => null

const store = createPinia()
const oem = createPinia()

// 先使用oem对象
app.use(oem)

// websocket
import createWebsocket from '@/websocket/websocket-factory.js'

setSiteInfos().then(() => {

    // @ts-ignore : 改变网站信息
    window.$CHANGE_INDEX_SITE_INFO()

    // 设置全局app对象
    setGlobalApp(app)

    app.config.globalProperties.$access = function(entId){
        let accessList = useUserStore().userInfo.entIdList
        return accessList && accessList.indexOf(entId) >= 0
    }

    app.config.globalProperties.$hasAgentEnt = function(){
        return true
    }

    app.config.globalProperties.$infoBox = infoBox
    
    // 挂载websocket
    app.config.globalProperties.$ws = createWebsocket()
    app.use(store).use(icons).use(router).use(ProLayout).use(VueViewer).use(VueClipboard).mount('#app')
    
})
